package com.inspection.controller.sys;

import com.inspection.entity.SysMenuDO;
import com.inspection.model.dto.SysMenuDTO;
import com.inspection.model.dto.SysMenuQueryDTO;
import com.inspection.service.SysMenuService;
import com.inspection.support.Wrapper;
import com.inspection.support.anno.SysLogAnno;
import com.inspection.support.model.MenuDataTree;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhaoqi
 * @since 2020-12-04
 */
@RestController
public class SysMenuController {

    @Autowired
    private SysMenuService sysMenuService;


    @RequestMapping("/sys/menu/manage")
    public Wrapper<MenuDataTree> menuManager(@RequestBody SysMenuQueryDTO query) {
        return Wrapper.ok(sysMenuService.getMenuManagerTree());
    }


    @SysLogAnno(operateCode =100301,operateName = "系统菜单：新增")
    @RequestMapping("/sys/menu/save")
    public Wrapper<String> saveMenu(@RequestBody SysMenuDTO save) {
        sysMenuService.saveMenu(save);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100302,operateName = "系统菜单：删除")
    @RequestMapping("/sys/menu/del")
    public Wrapper<String> delMenu(@RequestBody SysMenuDTO del) {
        sysMenuService.delMenu(del);
        return Wrapper.ok("ok");
    }

    @SysLogAnno(operateCode =100303,operateName = "系统菜单：更新")
    @RequestMapping("/sys/menu/update")
    public Wrapper<String> updateMenu(@RequestBody SysMenuDTO update) {
        sysMenuService.updateMenu(update);
        return Wrapper.ok("ok");
    }

}
